package com.itheima.queue;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  14:45 2020/7/26</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/7/26      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Configuration
public class QueueBean {

    /*
        创建hello queue
     */
    @Bean
    public Queue queue(){
        return new Queue("jiang_li_na");
    }

    /*
      创建fanout.A 队列
     */
    @Bean
    public Queue fanoutA(){
        return new Queue("fanout.A");
    }

    /*
      创建fanout.B 队列
     */
    @Bean
    public Queue fanoutB(){
        return new Queue("fanout.B");
    }

    /*
        创建fanout交换机
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout_ex");
    }

    /*
        将fanout.B队列完成与fanout_ex 交换机的绑定
     */
    @Bean
    Binding bindingFanoutA(FanoutExchange fanoutExchange, Queue fanoutA){
        return BindingBuilder.bind(fanoutA).to(fanoutExchange);
    }
    /*
        将fanout.B队列完成与fanout_ex 交换机的绑定
     */
    @Bean
    Binding bindingFanoutB(FanoutExchange fanoutExchange, Queue fanoutB){
        return BindingBuilder.bind(fanoutB).to(fanoutExchange);
    }

    /*
        创建direct.A 队列
     */
    @Bean
    public Queue directA(){
        return new Queue("direct.A");
    }

    /*
       创建direct.B 队列
    */
    @Bean
    public Queue directB(){
        return new Queue("direct.B");
    }

    /*
      创建direct ex
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct_ex");
    }

    /*
        将directA与directExchange 完成绑定并且设置routing key
     */
    @Bean
    Binding bindingDirectA(DirectExchange directExchange, Queue directA){
        return BindingBuilder.bind(directA).to(directExchange).with("itheima");
    }

    /*
       将directB与directExchange 完成绑定并且设置routing key
    */
    @Bean
    Binding bindingDirectB(DirectExchange directExchange, Queue directB){
        return BindingBuilder.bind(directB).to(directExchange).with("itcast");
    }

    /*
       创建topic.A 队列
    */
    @Bean
    public Queue topicA(){
        return new Queue("topic.A");
    }

    /*
       创建topic.B 队列
    */
    @Bean
    public Queue topicB(){
        return new Queue("topic.B");
    }
    /*
        创建topic交换机
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic_ex");
    }

    /*
        完成topic.A与交换机的绑定
        routingkey:
          itheima.a
          *号：不多不少routingkey后只可以有一个词 .
     */
    @Bean
    Binding bindingTopicA(TopicExchange topicExchange, Queue topicA){
        return BindingBuilder.bind(topicA).to(topicExchange).with("itheima.*");
    }

    /*
        完成topic.B与交换机的绑定
        routingkey:
          itheima
          itheima.a
          itheima.a.b
          #号：大于等于0个词
     */
    @Bean
    Binding bindingTopicB(TopicExchange topicExchange, Queue topicB){
        return BindingBuilder.bind(topicB).to(topicExchange).with("itheima.#");
    }
}
